package org.example.controller;

import org.example.domain.entity.ProductComments;
import org.example.domain.entity.ProductParams;
import org.example.domain.model.ProductAllInfo;
import org.example.domain.model.ProductCommentsModel;
import org.example.domain.model.Result;
import org.example.service.IProductParticularsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
//商品详情页修饰接口
public class ProductParticularsController {

    private IProductParticularsService productParticularsService;

    public ProductParticularsController(IProductParticularsService productParticularsService) {
        this.productParticularsService = productParticularsService;
    }

    @GetMapping("/show")
    public Result showAllInfo(Integer productId){
        ProductAllInfo productAllInfo = productParticularsService.selectProductAllInfo(productId);
        return Result.buildSuccess(productAllInfo);
    }

    @GetMapping("/particulars")
    public Result showParticulars(Integer productId){
        ProductParams productParams = productParticularsService.selectProductParamsById(productId);
        return Result.buildSuccess(productParams);
    }

    @GetMapping("/evaluate")
    public Result showEvaluate(Integer productId){
        List<ProductComments> productComments = productParticularsService.selectProductCommentsById(productId);
        if(productComments != null){
            return Result.buildSuccess(productComments);
        }else {
            return Result.buildFail("fail");
        }
    }



}
